package com.zephyr.vchcenter.service.impl;

import org.apache.log4j.Logger;

import com.zephyr.vchcenter.bean.Voucher;
import com.zephyr.vchcenter.bean.VoucherTemp;
import com.zephyr.vchcenter.dao.IBaseDao;
import com.zephyr.vchcenter.helper.SpringHelper;
import com.zephyr.vchcenter.service.IBatScanService;
import com.zephyr.vchcenter.service.ICreateProcessService;
import com.zephyr.vchcenter.util.XmlParseUtil;

public class BatScanServiceImpl implements IBatScanService {
	private static final Logger log = Logger
			.getLogger(BatScanServiceImpl.class);

	public String saveVoucher(String xmlinfo) {
		log.debug("xmlinfo: " + xmlinfo);
		Object obj = SpringHelper.getBean("baseDao");;
		IBaseDao baseDao=(IBaseDao)obj;
		VoucherTemp vouTmp = new VoucherTemp();
		XmlParseUtil xpu = new XmlParseUtil();
		try {
			vouTmp = xpu.getVouTmp4XML(xmlinfo);
			log.debug("vouTmp toString: " + vouTmp.toString());
			String fimgid = vouTmp.getFimgid();
			if(fimgid != null && !"".equals(fimgid)) {
				if(fimgid.length() > 32)
					return "faliure,front节点中imgid长度过大";	
			}
			
			String bimgid = vouTmp.getBimgid();
			if(bimgid != null && !"".equals(bimgid)) {
				if(bimgid.length() > 32)
					return "faliure,back节点中imgid长度过大";	
			}
			
			String accno = vouTmp.getAccno();
			if(accno != null && !"".equals(accno)) {
				if(accno.length() > 20)
					return "faliure,Accno长度过大";
			}
			
			String amount = vouTmp.getAmount();
			if(amount != null && !"".equals(amount)) {
				if(vouTmp.getAmount().length() > 20)
					return "faliure,Amount长度过大";
			}
			
			String exchno = vouTmp.getExchno();
			if(exchno != null && !"".equals(exchno)) {
				if(vouTmp.getExchno().length() > 20)
					return "faliure,Exchno长度过大";
			}
			
			String vchdate = vouTmp.getVchdate();
			if(vchdate != null && !"".equals(vchdate)) {
				if(vouTmp.getVchdate().length() > 20)
					return "faliure,Vchdate长度过大";
			}
			
			String vchno = vouTmp.getVchno();
			if(vchno != null && !"".equals(vchno)) {
				if(vouTmp.getVchno().length() > 20)
					return "faliure,Vchno长度过大";
			}
			
			String vchtype = vouTmp.getVchtype();
			if(vchtype != null && !"".equals(vchtype)) {
				if(vouTmp.getVchtype().length() > 20)
					return "faliure,Vchtype长度过大";
			}
			
			Voucher voucher = new Voucher();
			voucher.setAccno(vouTmp.getAccno());
			voucher.setAmount(vouTmp.getAmount());
			voucher.setVchno(vouTmp.getVchno());
			voucher.setVchtype(vouTmp.getVchtype());
			voucher.setVchdate(vouTmp.getVchdate());
			voucher.setExchno(vouTmp.getExchno());
			voucher.setFimgid(vouTmp.getFimgid());
			voucher.setBimgid(vouTmp.getBimgid());
			ICreateProcessService createpro=new CreateProcessImpl();
			createpro.createProcess(voucher);
		} catch (Exception e) {
			return "failure,"+e.getMessage();
		}
		
		return "success";
	}

}
